import {Select} from 'antd'
import React, {Component} from 'react'

interface IFilter {
  action?: Function;
  school?: any;
  getValue?: (value: any,name:string) => any;
  schoolName:string;
}

export default class FilterBySchool extends Component<IFilter, any> {
  constructor(props: IFilter) {
    super(props);
    this.state = {
    }
  }

  componentDidMount() {

  }

  onSelectChange(e: any, info: any) {
    const id = parseInt(info.key);
    const name = info.value;
    this.props.getValue?.(id,name);
  }

  render() {
    const {school} = this.props;
    return (
      <div style={{margin: 10, marginLeft: 22}}>
        <Select 
        placeholder={"请选择学校"} 
        style={{width: 300}} 
        showSearch 
        onChange={this.onSelectChange.bind(this)}
        value={this.props.schoolName}
        >
          {
            school.map((element: any, index: number) => {
              return <Select.Option key={element.id} value={element.name}>
                {element.name}
              </Select.Option>
            })
          }
        </Select>
      </div>
    )
  }
}
